<template>
	<view class="index-page with-tabbar" v-if="custom">
		<!-- 1. 顶部自定义导航栏 -->
		<div class="navTop pt-20 navTopFix">
			<div class="flex-center searchContent pb-20 bor-b">
				<div class="flex-center serchBox pr-6 pl-30  ">
					<div class="iconfont icon-sousuo "></div>
					<div class="searchInput ml-20">
						<input type="text" v-model="searchName" @input="serchNameInput" placeholder="请输入关键字"
							@confirm="handleConfirm" />
					</div>
					<div class="ml-auto iconfont icon-close1 pr-20 pl-20" @click="resetBtn"></div>
				</div>
			</div>
			<div class="flex-center justify-center align-center tabTitle">
				<div class="color-3 flex align-center justify-center fontS28" style="width: 50%; "
					v-for="(item, index) in typeList" :key="index" @click="tabClick(index)">
					<div :class="typeIndex === index ? 'activeCur' : ''">{{ item }}</div>
				</div>
			</div>

		</div>


		<!-- 页面主要内容区域 -->
		<view class="page-content pt-230">
			<!-- 服务列表 -->
			<view class="" v-if="typeIndex === 0">
				<div class="swiperContent">
					<view class="collect-card" v-for="(collect, index) in list" :key="index" @click="goJobDetail(job)">
						<image class="collect-img" :src="baseUrl + collect.carouselImageUrls" mode="aspectFill"></image>
						<div class="collect-info">
							<div class="flex align-center">
								<div class="fontS26 collect-name text-cut">{{ collect.serveName }}</div>
								<div class="ml-auto color-red fontS24">¥<span class="fontS32 font-weight">{{
									collect.presentPrice
								}}</span></div>
							</div>
							<div class="mt-6 color-96 fontS22 text-cut">{{ collect.serveIntroduction }}</div>
						</div>

					</view>
				</div>

				<view v-if="!noteServeFlag && !listLoad" class="pt-20 pb-20 color-6d text-center fontS28">没有更多数据
				</view>
				<without v-if="list.length < 1 && listLoad"></without>
			</view>
			<!-- 牛人列表 -->

			<view class="job-list-section" v-if="userInfo.userType === '03' && typeIndex === 1">


				<view class="job-card" v-for="(job, index) in personList" :key="index" @click="goPersonDetail(job)">
					<view class="card-tops flex-center">
						<text class="job-title">{{ job.name }}</text>
						<text class="job-exper fontS24  color-80 ml-40">{{ job.experienceRequire }}年 ｜ {{
							job.highEducationName }} ｜ {{
								job.exceptSalary }}</text>
					</view>

					<view class="card-tags" v-if="job.label">
						<text class="tag" v-for="tag in job.label.split(',')" :key="tag">{{ tag }}</text>
					</view>
					<view class="card-bottom mt-8">
						<view class="hr-info">
							<text class="hr-name fontS24 color-3"> {{ job.companyName || '' }} {{ job.companyName
								&& job.professionName ? '|' : '' }} {{ job.professionName || '' }}</text>
						</view>

					</view>
				</view>
				<view v-if="!noteComFlag && !personLoad" class="pt-20 pb-20 color-6d text-center fontS28">没有更多数据</view>
				<without v-if="personLoad"></without>
			</view>
			<!-- 5. 职位列表 -->
			<view v-if="userInfo.userType !== '03' && typeIndex === 1" class="job-list-section">
				<!-- 两级Tab结构 -->
				<view class="job-card" v-for="(job, index) in jobList" :key="index" @click="goJobDetail(job)">
					<view class="card-top">
						<text class="job-title">{{ job.professionName || '' }}</text>
						<text class="job-salary">{{ job.salary }}{{ job.salaryMonth ? '·' + job.salaryMonth + '薪' : ''
						}}</text>
					</view>
					<view class="card-company">
						<text>{{ job.companyName || '' }} {{ job.companySizeName || '' }}</text>
						<text class="card-company-location">{{ job.areaName || '' }}</text>
					</view>
					<view class="card-tags flex-center" v-if="job.postKey.length > 0">
						<div class="tag" v-for="tag in job.postKey.split(',')" :key="tag">{{ tag }}</div>
					</view>
					<view class="card-bottom">
						<view class="hr-info">
							<text class="hr-name">{{ job.creator || '' }}·{{ job.creatorPostName || '' }}</text>
						</view>
						<!-- <view class="online-status">
							<view class="dot"></view>
							<text>当前在线</text>
						</view> -->
					</view>
				</view>
				<view v-if="!noteFlag && !jobLoad" class="pt-20 pb-20 color-6d text-center fontS28">没有更多数据</view>
				<without v-if="jobLoad"></without>
			</view>
		</view>
		<bottom-tab-bar-com v-if="userInfo.userType === '03'" :tabIndexs="tabNum" />
		<bottom-tab-bar v-else :tabIndexs="tabNum" />

	</view>
</template>

<script>
import { findServePersonalsByName, findServeList, findCarouselImageListPerApp, findServeIconListCmpApp, resumeExpect, jobberQuery, companyQuery } from "@/api/index";

export default {
	data() {
		return {
			listLoad: false,
			personLoad: false,
			jobLoad: false,
			searchName: '',
			typeList: ['服务', '牛人'],
			typeIndex: 0,
			custom: null,
			baseUrl: getApp().globalData.baseUrl,
			jobList: [],
			noteFlag: true,
			params: {
				pageNo: 1,
				pageSize: 6,


			},

			// 企业端
			positionTabs: [],
			activeMainPTab: 0,
			paramsCom: {
				pageNo: 1,
				pageSize: 6,
				isRecommend: 1

			},
			personList: [],
			noteComFlag: true,
			// 服务
			serveParam: {
				pageNum: 1,
				pageSize: 10,
				serveName: ''
			},
			list: [],
			noteServeFlag: true
		};
	},

	computed: {
		userInfo() {
			console.log(this.$store.getters.userInfo)
			return this.$store.getters.userInfo || {};
		},
	},

	async onLoad(options) {
		this.custom = wx.getMenuButtonBoundingClientRect()
		this.typeList[1] = this.userInfo.userType === '03' ? '牛人' : '岗位'

		this.searchName = options.searchKey
		await this.serchFunction()
	},
	onReachBottom() {
		if (this.typeIndex === 0) {
			this.serveParam.pageNum++;
			if (this.noteServeFlag) {
				this.getServeList()
			}

		} else {
			if (this.userInfo.userType === '03') {
				this.paramsCom.pageNo++;
				if (this.noteComFlag) {
					this.getPersonList();
				}
			} else {
				this.params.pageNo++;
				if (this.noteFlag) {
					this.getJobList();
				}

			}
		}

	},
	methods: {
		async tabClick(i) {
			this.typeIndex = i
			await this.serchFunction()
		},
		async serchNameInput(e) {
			await this.serchFunction()
		},
		async resetBtn() {
			this.searchName = ''
			await this.serchFunction()
		},
		async handleConfirm(e) {
			await this.serchFunction()
		},
		async serchFunction() {
			this.params.pageNo = 1
			this.paramsCom.pageNo = 1
			this.serveParam.pageNo = 1
			if (this.typeIndex === 0) {
				this.serveParam.serveName = this.searchName
				this.getServeList()
			} else {
				if (this.userInfo.userType === '03') {
					this.paramsCom.searchKey = this.searchName
					await this.getPersonList()
				} else {
					this.params.searchKey = this.searchName
					await this.getJobList()
				}
			}
		},

		// 获取推荐服务列表
		async getServeList() {
			this.listLoad = false
			let api = this.userInfo.userType === '03' ? findServeList : findServePersonalsByName;
			const {
				rows
			} = await api(this.serveParam);
			if (rows.length < this.serveParam.pageSize) {
				this.noteServeFlag = false
			}

			this.list = this.serveParam.pageNum === 1 ? rows : [...this.list, ...rows];
			if (this.list.length < 1) {
				this.listLoad = true
			}
		},

		// 获取职位列表
		async getJobList() {
			this.jobLoad = false
			const {
				rows
			} = await jobberQuery(this.params);
			if (rows.length < this.params.pageSize) {
				this.noteFlag = false
			}
			this.jobList = this.params.pageNo === 1 ? rows : [...this.jobList, ...rows];
			if (this.jobList.length < 1) {
				this.jobLoad = true
			}
		},
		// 获取牛人列表
		async getPersonList() {
			this.personLoad = false
			const {
				rows
			} = await companyQuery(this.paramsCom);
			if (rows.length < this.paramsCom.pageSize) {
				this.noteComFlag = false
			}
			this.personList = this.params.pageNo === 1 ? rows : [...this.personList, ...rows];
			if (this.personList.length < 1) {
				this.personLoad = true
			}
		},

		// 跳转服务详情
		goDetail(type, item) {
			console.log(item)
			let id = ''
			if (type === 'banner') id = item.linkId
			if (type === 'serve') id = item.serveId
			uni.navigateTo({
				url: `/pages/service/serviceDetail?serveId=${id}`
			})

		},
		// 跳转职位详情
		goJobDetail(item) {

			uni.navigateTo({
				url: `/pages/position/detail?positionId=${item.positionId}`
			})
		},
		goPersonDetail(item) {
			uni.navigateTo({
				url: `/pages/position/resume?userId=${item.userId}`
			})
		},


	}
};
</script>

<style lang="less" scoped>
@import url(home.less);
</style>